﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Services;

namespace MenusHunter.Services
{
    /// <summary>
    /// Summary description for FoodsManager1
    /// </summary>
    [WebService(Namespace = "http://menuhunter.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
   [System.Web.Script.Services.ScriptService]
    public class FoodsManager1 : System.Web.Services.WebService
    {
        
        [WebMethod]
        public List<Entities.Food> GetListFoodByRestaurant(int restaurantId)
        {
            using (var db = new MenusHunterDataContext())
            {
                
                return (from item in db.Foods
                        where item.RestaurantId == restaurantId
                        select
                            new Entities.Food()
                                {
                                    Name = item.Name,
                                    Description = item.Description,
                                    Price = (decimal) item.Price,
                                    Currency = item.Currency,
                                    RestaurantId = (int) item.RestaurantId,
                                    Id = item.Id,
                                    DateCreate = (DateTime) item.DateCreate
                                }).ToList();
            }
        }


        [WebMethod]
        public int NewFood(int restaurantId, string name, string description, string image, decimal price, string currency, int status)
        {
            using (var db = new MenusHunterDataContext())
            {
                var item = new Food()
                               {
                                   RestaurantId = restaurantId,
                                   Name = name,
                                   Description = description,
                                   ImgesUrl = image,
                                   Currency = currency,
                                   Price = price,
                                   DateCreate = DateTime.Now,
                                   Status = status
                               };
                db.Foods.InsertOnSubmit(item);
                db.SubmitChanges();

                return item.Id;
            }
        }
    }
}
